{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# This notebook assumes to be running from your FireCARES VM (eg. python manage.py shell_plus --notebook --no-browser)\n",
    "\n",
    "import sys\n",
    "import os\n",
    "import time\n",
    "import pandas as pd\n",
    "pd.set_option('display.max_columns', 100)\n",
    "pd.set_option('display.max_rows', 1000)\n",
    "import numpy as np\n",
    "sys.path.insert(0, os.path.realpath('..'))\n",
    "import folium\n",
    "import django\n",
    "import sqlite3\n",
    "django.setup()\n",
    "from django.db import connections\n",
    "from pretty import pprint\n",
    "from IPython.display import display"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "df = pd.read_csv('../predictions.2015.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Those with empty predicted fires/fire spreads/deaths/ by structure hazard level, yet have a score\n",
    "\n",
    "q = \"\"\"\n",
    "select department_id, level\n",
    "from firestation_firedepartmentriskmodels\n",
    "where dist_model_score is not null\n",
    "    and (risk_model_fires is null or risk_model_fires_size1 is null or risk_model_fires_size2 is null or risk_model_deaths is null or risk_model_injuries is null)\n",
    "order by department_id\n",
    "\"\"\"\n",
    "\n",
    "pd.read_sql_query(q, connections['default'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Counts by region/size\n",
    "\n",
    "df2 = df[df['fd_id'].isnull() == False].groupby(['region', 'fd_size']).count()\n",
    "display(df2)\n",
    "df2.to_csv('/tmp/outf.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "# Fire spread percentages, but no original fire prediction...\n",
    "df[df['lr_size_2'].notnull() & df['lr_fire'].isnull()]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
